import { db_set, db_set_obj, db_get_bool, db_get_float, db_get_int, db_get_str } from './base';

const g_stepnum = () => db_get_int("stepnum");          // stepnum
const s_stepnum = (v) => db_set("stepnum", v);          // stepnum

const g_state = () => db_get_str("state");              // state
const s_state = (v) => db_set("state", v);              // state

const g_gun = () => db_get_str("gun");                  // gun
const s_gun = (v) => db_set("gun", v);                  // gun

const g_psn = () => db_get_str("psn");                  // psn
const s_psn = (v) => db_set("psn", v);                  // psn

const g_model = () => db_get_str("model");              // model
const s_model = (v) => db_set("model", v);              // model

const g_wsn = () => db_get_str("wsn");                  // wsn
const s_wsn = (v) => db_set("wsn", v);                  // wsn

const g_line = () => db_get_str("line");                // line
const s_line = (v) => db_set("line", v);                // line

const g_db = {
    input:          (v) =>      db_set("input", v),
    is_input:       () => db_get_bool("input"),
    start_scan:     () =>      db_set("scan", false),
    stop_scan:      () =>      db_set("scan", true),
    is_stop_scan:   () => db_get_bool("scan"),
    box:            () =>  db_get_str("box"),
    s_box:          (v) =>     db_set("box", v),
    boxtp:          () =>  db_get_str("boxtp"),
    s_boxtp:        (v) =>     db_set("boxtp", v),
    boxtray:        () =>  db_get_int("boxtray"),
    s_boxtray:      (v) =>     db_set("boxtray", v),
    boxlv:          () =>  db_get_int("boxlv"),
    s_boxlv:        (v) =>     db_set("boxlv", v),
    num:            () =>  db_get_int("num"),
    s_num:          (v) =>     db_set("num", v),
    sum:            () =>  db_get_int("sum"),
    s_sum:          (v) =>     db_set("sum", v),
    pnum:           () =>  db_get_int("pnum"),
    s_pnum:         (v) =>     db_set("pnum", v),
    task:           () =>  db_get_str("task"),
    s_task:         (v) =>     db_set("task", v),
    msn:            () =>  db_get_str("msn"),
    s_msn:          (v) =>     db_set("msn", v),
    next:           () =>  db_get_str("next"),
    s_next:         (v) =>     db_set("next", v),
    tech:           () =>  db_get_str("tech"),
    s_tech:         (v) =>     db_set("tech", v),
    dia_min:        () =>  db_get_float("dia_min"),
    dia_max:        () =>  db_get_float("dia_max"),
    dt_min:         () =>  db_get_float("dt_min"),
    dt_max:         () =>  db_get_float("dt_max"),
    w_min:          () =>  db_get_float("w_min"),
    w_max:          () =>  db_get_float("w_max"),
    s_dia_min:      (v) =>  db_set("dia_min", v),
    s_dia_max:      (v) =>  db_set("dia_max", v),
    s_dt_min:       (v) =>  db_set("dt_min", v),
    s_dt_max:       (v) =>  db_set("dt_max", v),
    s_w_min:        (v) =>  db_set("w_min", v),
    s_w_max:        (v) =>  db_set("w_max", v),
    seal:           () =>  db_get_str("seal"),
    s_seal:         (v) =>     db_set("seal", v),
    lub:            () =>  db_get_str("lub"),
    s_lub:          (v) =>     db_set("lub", v),
    lub_tag:        () =>  db_get_str("lub_tag"),
    s_lub_tag:      (v) =>     db_set("lub_tag", v),
    usn:            () =>  db_get_str("usn"),
    s_usn:          (v) =>     db_set("usn", v),
    mfc:            () =>  db_get_str("mfc"),
    s_mfc:          (v) =>     db_set("mfc", v),
    qyd:            () =>  db_get_str("qyd"),
    s_qyd:          (v) =>     db_set("qyd", v),
};

const clear_step = () => db_set_obj({
    stepnum: 0,
    state: "ready",
    num: 0,
    sum: 0,
    pnum: 0,
    gun: "",
    box: "",
    psn: "",
    msn: "",
    task: "",
    next: "",
    boxtp: "",
});

export {g_db, g_stepnum, g_wsn, g_state, g_gun, g_psn, g_model, g_line, clear_step, s_stepnum, s_state, s_model, s_wsn, s_line, s_psn, s_gun};
